package com.wechatapp.mengyao.poetry.core;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yanghuaxu
 * @date 2025/5/11 21:08
 */
@Getter
@Setter
public class PageResult<T> implements Serializable {
    private int pageNum;      // 当前页码
    private int pageSize;     // 每页数量
    private long total;       // 总记录数
    private int pages;        // 总页数
    private List<T> list;     // 当前页数据列表

    // 构造方法
    public PageResult(int pageNum, int pageSize, long total, int pages, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.pages = pages;
        this.list = list;
    }

    public static <T, E> PageResult<T> fromPage(Page<E> page, List<T> data) {
        return new PageResult<>(
                page.getPageNum(),
                page.getPageSize(),
                page.getTotal(),
                page.getPages(),
                data
        );
    }
}